/**
 * Created by Administrator on 2014/4/7.
 */
TileMc = cc.Layer.extend({
    iconSp: null,
    selectSp: null,
    isSelected: false,
    mPot: new Pot(0, 0),
    init: function (type) {
        this.iconSp = cc.Sprite.createWithSpriteFrameName("pic" + type + ".png");
        this.addChild(this.iconSp);
        this.selectSp = cc.Sprite.createWithSpriteFrameName("select.png");
        this.addChild(this.selectSp, 10);
        this.selectSp.setVisible(false);
    }
});

TileMc.create = function (type) {
    var tile = new TileMc();
    tile.init(type);
    return tile;
}
TileMc.prototype.select = function (flag) {
    if (arguments.length == 0) {
        return this.isSelected;
    } else {
        this.isSelected = flag;
        this.selectSp.setVisible(flag);
        if (this.isSelected) { //选中了
            var scaleAction = cc.ScaleBy.create(0.5, 1.1);
            this.selectSp.runAction(cc.RepeatForever.create(
                cc.Sequence.create(scaleAction, scaleAction.reverse())));
            //播放声音
            SoundManager.playEffect(SoundManager.PATH_SELECT);
        } else {
            this.selectSp.removeAllActions();
        }
    }
}
TileMc.prototype.index = function (type) {
    if (arguments.length == 0) {
        return this.type;
    } else {
        this.type = type;
        var frame = cc.SpriteFrameCache.getInstance().getSpriteFrame("pic" + type + ".png");
        this.iconSp.setDisplayFrame(frame);
    }
}
TileMc.prototype.point = function (row, line) {
    if (arguments.length == 0) {
        return this.mPot;
    } else {
        this.mPot.r = row;
        this.mPot.l = line;
    }
}
TileMc.prototype.dispose = function(){
    //播放爆炸效果
    this.removeAllChildren();
    var explore = cc.Sprite.create();
    this.addChild(explore);
    var exploreAnim = cc.AnimationCache.getInstance().getAnimation("explore");
    explore.runAction(cc.Animate.create(exploreAnim));
}